package com.thssh.ui.lsn13.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SwitchCompat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.CompoundButton;

import com.thssh.ui.R;
import com.thssh.ui.lsn13.view.CustomLayout;
import com.thssh.ui.lsn13.view.CustomView;

public class TouchEventActivity extends AppCompatActivity implements CompoundButton.OnCheckedChangeListener {

    private CustomView custom_view;
    private CustomLayout custom_layout;

    private SwitchCompat view_on_touch_event_switcher;
    private SwitchCompat disallow_intercept_switcher;
    private SwitchCompat view_group_on_touch_event_switcher;
    private SwitchCompat view_on_intercept_touch_event_switcher;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_touch_event);
        custom_view = (CustomView) findViewById(R.id.custom_view);
        custom_layout = (CustomLayout) findViewById(R.id.custom_layout);
        view_on_touch_event_switcher = (SwitchCompat) findViewById(R.id.view_on_touch_event_switcher);
        disallow_intercept_switcher = (SwitchCompat) findViewById(R.id.disallow_intercept_switcher);
        view_group_on_touch_event_switcher = (SwitchCompat) findViewById(R.id.view_group_on_touch_event_switcher);
        view_on_intercept_touch_event_switcher = (SwitchCompat) findViewById(R.id.view_on_intercept_touch_event_switcher);

        view_on_touch_event_switcher.setOnCheckedChangeListener(this);
        disallow_intercept_switcher.setOnCheckedChangeListener(this);
        view_group_on_touch_event_switcher.setOnCheckedChangeListener(this);
        view_on_intercept_touch_event_switcher.setOnCheckedChangeListener(this);

    }

    public void customViewClick(View view) {
        Log.d("TouchEventActivity", "customViewClick: ");
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean handled = super.onTouchEvent(event);
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                Log.d("TouchEventActivity", "onTouchEvent: ACTION_DOWN " + handled);
                break;
            case MotionEvent.ACTION_MOVE:
                Log.d("TouchEventActivity", "onTouchEvent: ACTION_MOVE " + handled);
                break;
            case MotionEvent.ACTION_UP:
                Log.d("TouchEventActivity", "onTouchEvent: ACTION_UP " + handled);
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.d("TouchEventActivity", "onTouchEvent: ACTION_CANCEL " + handled);
                break;
            default:
                Log.d("TouchEventActivity", "onTouchEvent: " + event.getAction() + "  " + handled);
                break;
        }
        return handled;
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()){
            case R.id.view_on_touch_event_switcher:
                custom_view.setOnTouchEventHandled(isChecked);
                break;
            case R.id.disallow_intercept_switcher:
                custom_view.setDisallowIntercept(isChecked);
                break;
            case R.id.view_group_on_touch_event_switcher:
                custom_layout.setOnTouchEventHandled(isChecked);
                break;
            case R.id.view_on_intercept_touch_event_switcher:
                custom_layout.setOnInterceptTouchEventHandled(isChecked);
                break;
            default:
                break;
        }
    }
}
